/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * UserView.java
 *
 * Created on 24-abr-2012, 23:57:13
 */
package educar.abmDocente;

import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
/*__________________________________________________________________________________________*/
/*__________________________________________________________________________________________*/
/**
 * <hr>
 * DocenteView: En esta clase se encuantran los metodos necesarios para implementar una ventana
 * que permite agregar, eliminar, moficar y buscar un docente en el sistema
 * 
 * @author Gaston
 * <hr>
 */
/*__________________________________________________________________________________________*/
/*__________________________________________________________________________________________*/
public class DocenteView extends javax.swing.JFrame {

// <editor-fold defaultstate="collapsed" desc="Constructor">
    public DocenteView() {
        initComponents();
    }
    // </editor-fold>
   
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jbAgregar = new javax.swing.JButton();
        jbEliminar = new javax.swing.JButton();
        jbBuscar = new javax.swing.JButton();
        jScrollPane = new javax.swing.JScrollPane();
        jtDocente = new javax.swing.JTable();
        jlTitulo = new javax.swing.JLabel();
        jtfCriterio = new javax.swing.JTextField();
        jlCriterio = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jbAgregar.setText("Agregar");

        jbEliminar.setText("Eliminar");

        jbBuscar.setText("Buscar");

        jtDocente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "", "Dni", "Nombre y apellido", "Direccion"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane.setViewportView(jtDocente);
        jtDocente.getColumnModel().getColumn(0).setResizable(false);
        jtDocente.getColumnModel().getColumn(0).setPreferredWidth(15);

        jlTitulo.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jlTitulo.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jlTitulo.setText("Administracion de Docente");

        jlCriterio.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jlCriterio.setText("Dni de Docente xx.xxx.xxx");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jtfCriterio, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE)
                    .addComponent(jlCriterio, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE))
                .addContainerGap())
            .addComponent(jlTitulo, javax.swing.GroupLayout.DEFAULT_SIZE, 474, Short.MAX_VALUE)
            .addComponent(jScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 474, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jlTitulo)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbEliminar, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jbBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jlCriterio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtfCriterio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
 
//<editor-fold defaultstate="collapsed" desc=" Declaracion de Variables ">
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane;
    private javax.swing.JButton jbAgregar;
    private javax.swing.JButton jbBuscar;
    private javax.swing.JButton jbEliminar;
    private javax.swing.JLabel jlCriterio;
    private javax.swing.JLabel jlTitulo;
    private javax.swing.JTable jtDocente;
    private javax.swing.JTextField jtfCriterio;
    // End of variables declaration//GEN-END:variables
//</editor-fold>

    /**
     * 
     * @return jtDocente
     */
    public JTable getJTDocente(){
        return this.jtDocente;
    }

    /**
     * 
     * @return 
     */
    public DefaultTableModel getModeloTabla(){
        return (DefaultTableModel) jtDocente.getModel();
    }
    
    /**
     * setModelTabla(): este metodo modifica el modelo de una tabla, dependiendo del parametro que reciba
     * puede crear una tabla vacia o si recibe una tabla con elementos inserta esta nueva tabla en la tabla anterior
     * 
     * @param tabla 
     */
    public void setModeloTabla(DefaultTableModel tabla){
        if (tabla == null){ 
            jtDocente.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "", "Dni", "Nombre y apellido", "Direccion"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });       
        } else {
            this.jtDocente.setModel(tabla);
        }    
        jtDocente.getTableHeader().setReorderingAllowed(false);
        jScrollPane.setViewportView(jtDocente);
        jtDocente.getColumnModel().getColumn(0).setResizable(false);
        jtDocente.getColumnModel().getColumn(0).setPreferredWidth(50);
        jtDocente.getColumnModel().getColumn(1).setPreferredWidth(160);
        jtDocente.getColumnModel().getColumn(2).setPreferredWidth(160);
        jtDocente.getColumnModel().getColumn(3).setPreferredWidth(160);
    }//Fin de la clase setModeloTabla().
    
    
    /**
     * 
     * @return jbAgregar
     */
    public JButton getJbAgregar() {
        return jbAgregar;
    }

    /**
     * 
     * @return jbBuscar
     */
    public JButton getJbBuscar() {
        return jbBuscar;
    }

    /**
     * 
     * @return jbEliminar
     */
    public JButton getJbEliminar() {
        return jbEliminar;
    }

    /**
     * 
     * @return jtfCriterio
     */
    public String getCriterio() {
        return jtfCriterio.getText();
    }

    /**
     * 
     * @param listener 
     */
    public void setActionListener(DocenteController listener) {
        jbAgregar.addActionListener(listener);
        jbEliminar.addActionListener(listener);
        jbBuscar.addActionListener(listener);
    }

    /**
     * 
     * @param listener 
     */
    public void setMouseListener(DocenteController listener) {
        jtDocente.addMouseListener(listener);
    }

    /**
     * 
     * @param listener 
     */
    public void setWindowListener(DocenteController listener){
        this.addWindowListener(listener);
    }


}//Fin de la clase DocenteView()
